#ifndef ____MUTEX_HPP____
#define ____MUTEX_HPP____
#include <iostream>
#include <pthread.h>
#include <string>
#include <vector>
namespace Mutex
{
    class mutex
    {
    public:
        mutex()
        {
            pthread_mutex_init(&lock, nullptr);
        }

        ~mutex()
        {
            pthread_mutex_destroy(&lock);
        }

        void Lock()
        {
            pthread_mutex_lock(&lock);
        }

        void unLock()
        {
            pthread_mutex_unlock(&lock);
        }

        pthread_mutex_t* operator&() 
        {
            return &lock;
        }

    private:
        pthread_mutex_t lock;
    };

    // struct data
    // {
    // public:
    //     data()
    //     {}

        
    //     data(std::string name, pthread_mutex_t *pmutex)
    //         :_name(name)
    //         ,_pmutex(pmutex)
    //     {
    //     }
    //     ~data()
    //     {}

    //     std::string _name;
    //     pthread_mutex_t *_pmutex = nullptr;
    // };

    class AutoLock
    {
    public:
        AutoLock(mutex& lock)
            :_lock(lock)
        {
            _lock.Lock();
        }

        ~AutoLock()
        {
            _lock.unLock();
        }

    
    private:
        mutex& _lock;
    };

}


#endif
